package com.jrtc.service.impl;

import com.jrtc.base.entity.bo.Patient;
import com.jrtc.base.entity.bo.PatientRiskDescription;
import com.jrtc.base.entity.bo.RiskDescription;
import com.jrtc.base.entity.vo.PatientDescriptionVo;
import com.jrtc.dao.DepartmentDao;
import com.jrtc.dao.PatientDao;
import com.jrtc.dao.PatientRiskDescriptionDao;
import com.jrtc.dao.RiskDescriptionDao;
import com.jrtc.service.PatientRiskDescriptionService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("patientRiskDescriptionService")
public class PatientRiskDescriptionServiceImpl implements PatientRiskDescriptionService {
    @Resource
    private PatientRiskDescriptionDao patientRiskDescriptionDao;
    @Resource
    private PatientDao patientDao;
    @Resource
    private RiskDescriptionDao riskDescriptionDao;

    /**
     * 患者证件号获取疾病风险
     * */
    @Override
    public List<PatientDescriptionVo> descriptionByIdCard(String idCard) {
        List<PatientDescriptionVo> patientDescriptionVoList = new ArrayList<>();
        Patient patient = patientDao.licenseNumExercise(idCard);
        if (patient != null){
            List<PatientRiskDescription> patientRiskDescriptions;
            patientRiskDescriptions = patientRiskDescriptionDao.descriptionByIdCard(patient.getPatientId());
            if (patientRiskDescriptions != null && patientRiskDescriptions.size() > 0){
//                for (PatientRiskDescription patientRiskDescription : patientRiskDescriptions) {
//                    PatientDescriptionVo patientDescriptionVo = new PatientDescriptionVo();
//                    patientDescriptionVo.setCount(patientRiskDescription.getRiskCount());
//
//                    RiskDescription riskDescriptions = riskDescriptionDao.descriptionByIdCard(patientRiskDescription.getRiskDescriptionId());
//                    if (riskDescriptions != null){
//                        patientDescriptionVo.setUrl(riskDescriptions.getRiskDescriptionUrl());
//                        patientDescriptionVo.setName(riskDescriptions.getRiskDescriptionName());
//                    }
//                    patientDescriptionVoList.add(patientDescriptionVo);
//                }
            }
            else {
                patientRiskDescriptions = patientRiskDescriptionDao.descriptionByIdCard(1);
            }

            for (PatientRiskDescription patientRiskDescription : patientRiskDescriptions) {
                PatientDescriptionVo patientDescriptionVo = new PatientDescriptionVo();
                patientDescriptionVo.setCount(patientRiskDescription.getRiskCount());

                RiskDescription riskDescriptions = riskDescriptionDao.descriptionByIdCard(patientRiskDescription.getRiskDescriptionId());
                if (riskDescriptions != null){
                    patientDescriptionVo.setUrl(riskDescriptions.getRiskDescriptionUrl());
                    patientDescriptionVo.setName(riskDescriptions.getRiskDescriptionName());
                }
                patientDescriptionVoList.add(patientDescriptionVo);
            }

        }
        return patientDescriptionVoList;
    }
}